package gui;


import pojo.User;
import service.UserService;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class login {
    private JPanel panel1;
    private JTextField textField1;
    private JPasswordField passwordField1;
    private JButton 登录Button;

    public login() {
        登录Button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                User u = new User();
                u.setId(Integer.parseInt(textField1.getText()));
                u.setPasswd(passwordField1.getText());
                try {
                    if (UserService.login(u)) {
                        System.out.println("登录成功");
                        mainWindow m = new mainWindow();
                        m.show();
                    } else {
                        System.out.println("登录失败");
                        loginfaild dialog = new loginfaild();
                        dialog.pack();
                        dialog.setVisible(true);

                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }


            }
        });
    }

    public void show() {
        JFrame frame = new JFrame("登录");
        frame.setContentPane(new login().panel1);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);


    }
}
